package crm.view.campaign;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.Dimension;
import javax.swing.JSeparator;

import crm.viewframework.Validater;



import java.awt.Font;
import java.awt.event.ActionListener;

@SuppressWarnings({ "unused", "serial" })
public class CampaignHome extends JPanel
{
	private JTable table;
	private JTextField tStartDate;
	private JButton btnApplyFilter;
	private JComboBox comboCreatedBy;
	private JButton btnStartDate;
	
	public CampaignHome() 
	{
		SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
		
		JLabel lblStartDate = new JLabel("Start Date");
		lblStartDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblStartDate, 30, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, lblStartDate, 30, SpringLayout.WEST, this);
		add(lblStartDate);
		
		tStartDate = new JTextField();
		tStartDate.setEditable(false);
		tStartDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tStartDate, 6, SpringLayout.SOUTH, lblStartDate);
		springLayout.putConstraint(SpringLayout.WEST, tStartDate, 30, SpringLayout.WEST,this);
		add(tStartDate);
		tStartDate.setColumns(10);
		
		btnStartDate=new JButton();
		btnStartDate.setText("Cl");
		springLayout.putConstraint(SpringLayout.NORTH, btnStartDate, 0, SpringLayout.NORTH,tStartDate);
		springLayout.putConstraint(SpringLayout.WEST,btnStartDate , 10, SpringLayout.EAST, tStartDate);
		springLayout.putConstraint(SpringLayout.SOUTH, btnStartDate, 0, SpringLayout.SOUTH, tStartDate);
		add(btnStartDate);
		btnStartDate.setActionCommand("btnStartDate");
		
		comboCreatedBy = new JComboBox();
		springLayout.putConstraint(SpringLayout.NORTH, comboCreatedBy, 53, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, comboCreatedBy, 30, SpringLayout.EAST, btnStartDate);
		comboCreatedBy.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		comboCreatedBy.setPreferredSize(new Dimension(250, 23));
		add(comboCreatedBy);
		
		btnApplyFilter = new JButton("Apply Filter");
		springLayout.putConstraint(SpringLayout.NORTH, btnApplyFilter, 53, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, btnApplyFilter, 30, SpringLayout.EAST, comboCreatedBy);
		btnApplyFilter.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		add(btnApplyFilter);
		btnApplyFilter.setActionCommand("Apply Filter");
		
		JSeparator separator = new JSeparator();
		springLayout.putConstraint(SpringLayout.NORTH, separator, 30, SpringLayout.SOUTH, tStartDate);
		springLayout.putConstraint(SpringLayout.WEST, separator, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, separator, -30, SpringLayout.EAST, this);
		add(separator);
		
		JScrollPane scrollPane = new JScrollPane();
		springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 30, SpringLayout.NORTH,separator);
		springLayout.putConstraint(SpringLayout.WEST, scrollPane, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -30, SpringLayout.SOUTH, this);
		springLayout.putConstraint(SpringLayout.EAST, scrollPane, -30, SpringLayout.EAST, this);
		add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"CampaignName", "CreatedBy", "StartDate", "EndDate", "Description", "GO TO"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false, false, false, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		scrollPane.setViewportView(table);	
		table.setRowHeight(30);
	}
	
	public JTable getTable() {
		return table;
	}
	public void setTable(JTable table) {
		this.table = table;
	}
	public JTextField gettStartDate() {
		return tStartDate;
	}
	public void settStartDate(JTextField tStartDate) {
		this.tStartDate = tStartDate;
	}
	public JButton getBtnApplyFilter() {
		return btnApplyFilter;
	}
	public void setBtnApplyFilter(JButton btnApplyFilter) {
		this.btnApplyFilter = btnApplyFilter;
	}
	public JComboBox getComboCreatedBy() {
		return comboCreatedBy;
	}
	public void setComboCreatedBy(JComboBox comboCreatedBy) {
		this.comboCreatedBy = comboCreatedBy;
	}	
	public JButton getBtnCl1() {
		return btnStartDate;
	}
	public void setBtnCl1(JButton btnCl1) {
		this.btnStartDate = btnCl1;
	}
	
	public void actionListener(ActionListener al)
	{
		btnApplyFilter.addActionListener(al);
		btnStartDate.addActionListener(al);
	}
}
